/**
 * @projectName: api-backend
 * @package: com.wangzz.project.listener
 * @className: SmsListener
 * @author: wangzz
 * @description: TODO
 * @date: 2024/3/18 17:14
 * @version: 1.0
 */

package com.wangzz.apisms.listener;

import com.rabbitmq.client.Channel;
import com.wangzz.apisms.utils.SendMessageUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.util.Map;

import static com.wangzz.apicommon.constant.RabbitMqConstants.QUEUE_SMS_INFORM;

/**
 * @Author: wangzz
 * @Description: 监听验证码
 * @DateTime: 2024/3/18 17:14
 **/
@Slf4j
@Component
public class SmsListener {

    @RabbitListener(queuesToDeclare = {@Queue(QUEUE_SMS_INFORM)})
    public void receiveSms(Map<String, String> map, Message message, Channel channel) throws Exception {
        log.info("收到验证码：{}", map);
        channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);

        // 发送验证码
        SendMessageUtil.sendMessage(map);
    }
}